001 /**
002 * Created by IntelliJ IDEA.
003 * User: Wei Wang
004 * Date: Nov 28, 2002
005 * Time: 3:12:09 AM
006 */
007
008 package EVolve.util.painters;
009
010 import EVolve.visualization.AutoImage;
011
012 import java.awt.*;
013 import java.util.Stack;
014
015 public class StackHotspotPainter extends Painter{
016 private Stack currentStack;
017
018 public String getName() {
019 return "Stack Hotspot Painter";
020 }
021
022 public void paint(AutoImage image, long x, long y, long z) {
023
024 if (z == Integer.MAX_VALUE) {// method return;
025 image.setColor((int)x,(int)y,Color.black);
026 if (!currentStack.empty()) {
027 currentStack.pop();
028 if (!currentStack.empty()) {
029 image.setColor((int)x,((Long)currentStack.peek()).intValue(),Color.red );
030 }
031 }
032 } else {
033 for (int i=0; i<currentStack.size(); i++) {
034 image.setColor((int)x,((Long)currentStack.get(i)).intValue(),Color.blue);
035 }
036 image.setColor((int)x,(int)y,Color.red);
037 currentStack.push(new Long(y));
038 }
039 }
040
041 public void setStack(Stack stack) {
042 currentStack = stack;
043 }
044
045 public Object clone() {
046 StackHotspotPainter o = (StackHotspotPainter)super.clone();
047 o.currentStack = (Stack)currentStack.clone();
048 return o;
049 }
050 }